from threading import Thread, Lock
from time import sleep
from threading import Condition
lock = Lock()
total = 0


def add():
    global lock, total
    for i in range(100):
        lock.acquire()
        total += 1
        print('this is lock for add(1)  & a:{}'.format(total))
        # sleep(1)
        lock.release()


def desc():
    global lock, total
    for i in range(100):
        lock.acquire()
        total -= 1
        print('this is lock for desc(1)  & a:{}'.format(total))
        # sleep(1)
        lock.release()


if __name__ == '__main__':
    t1 = Thread(target=add, args=())
    t2 = Thread(target=desc, args=())
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print("total:{}".format(total))
